package com.feemanage.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.common.annotation.Anonymous;
import com.common.core.domain.AjaxResult;
import com.common.core.page.PageDomain;
import com.common.core.page.TableDataInfo;
import com.common.utils.poi.ExcelUtil;
import com.feemanage.domain.bo.ProjectTypeExecuteBo;
import com.feemanage.domain.vo.ProjectBudgetExecuteVo;
import com.feemanage.domain.vo.ProjectExecuteVo;
import com.feemanage.domain.vo.ProjectTypeExecuteVo;
import com.feemanage.domain.vo.ProjectUnitExecuteVo;
import com.feemanage.service.IProjectTypeExecuteService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 经费执行进度
 */
@Api(tags="经费执行进度")
@RestController
@RequestMapping("/feemanage/execute")
public class ProjectTypeExecuteController {

    @Autowired
    private IProjectTypeExecuteService baseService;

    /**
     * 项目分类执行率
     * @param executeBo
     * @return
     */
    @ApiOperation("项目分类执行率")
    @GetMapping("/list")
    public AjaxResult list(PageDomain pageDomain,ProjectTypeExecuteBo executeBo){
        List<ProjectTypeExecuteVo> list = baseService.selectList(pageDomain,executeBo,null);
        return AjaxResult.success(list);
    }

    @ApiOperation("导出项目分类执行率")
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestBody PageDomain pageDomain, @RequestBody ProjectTypeExecuteBo executeBo)
    {
        List <ProjectTypeExecuteVo> list = baseService.selectList(pageDomain,executeBo,"export");
        ExcelUtil<ProjectTypeExecuteVo> util = new ExcelUtil<>(ProjectTypeExecuteVo.class);
        util.exportExcel(response, list, "项目分类执行率","项目分类执行率");
    }

    /**
     * 学院经费执行率
     * @param executeBo
     * @return
     */
    @ApiOperation("学院经费执行率")
    @GetMapping("/unitlist")
    public TableDataInfo unitlist(PageDomain pageDomain,ProjectTypeExecuteBo executeBo){
        IPage<ProjectUnitExecuteVo> page = baseService.selectUnitList(pageDomain,executeBo);
        return TableDataInfo.build(page.getRecords(),page.getTotal());
    }

    @ApiOperation("导出学院经费执行率")
    @PostMapping("/exportunit")
    public void exportunit(HttpServletResponse response,@RequestBody PageDomain pageDomain,  @RequestBody ProjectTypeExecuteBo executeBo) {

        List <ProjectUnitExecuteVo> list = baseService.selectExportUnitList(pageDomain,executeBo);
        ExcelUtil<ProjectUnitExecuteVo> util = new ExcelUtil<>(ProjectUnitExecuteVo.class);
        util.exportExcel(response, list, "学院经费执行率","学院经费执行率");
    }

    /**
     * 项目经费执行率
     * @param executeBo
     * @return
     */
    @ApiOperation("项目经费执行率")
    @GetMapping("/projectlist")
    public TableDataInfo projectlist(PageDomain pageDomain, ProjectTypeExecuteBo executeBo){
        IPage<ProjectExecuteVo> page = baseService.selectprojectList(pageDomain,executeBo);
        return TableDataInfo.build(page.getRecords(),page.getTotal());
    }

    @ApiOperation("导出项目经费执行率")
    @PostMapping("/exportpro")
    public void exportproject(HttpServletResponse response,@RequestBody PageDomain pageDomain,  @RequestBody ProjectTypeExecuteBo executeBo)
    {
        List <ProjectExecuteVo> list = baseService.selectExportProList(pageDomain,executeBo);
        ExcelUtil<ProjectExecuteVo> util = new ExcelUtil<>(ProjectExecuteVo.class);
        util.exportExcel(response, list, "项目经费执行率","项目经费执行率");
    }

    /**
     * 预算科目经费执行率
     * @param executeBo
     * @return
     */
    @ApiOperation("预算科目经费执行率")
    @GetMapping("/budgetlist")
    public AjaxResult budgetlist(ProjectTypeExecuteBo executeBo){
        List<ProjectBudgetExecuteVo> list = baseService.selectbudgetList(executeBo);
        return AjaxResult.success(list);
    }
}
